const mysql = require('mysql');
var dbconfig = require('../config/db');
var pool = mysql.createPool(dbconfig)

exports.base = (sql, data, callback) => {
    var type = 1
    pool.getConnection(function (error,connection){
        if(error){type = 0,console.log(error)}
        else{
            //console.log("连接成功")
            connection.query(sql,data,function(error,results){
                if(error){type = 0,console.log(error)}
                else{
                    callback({
                        results: results,
                        type: type
                    })
                    connection.release()
                }
            })
        }
    })
}


// const mysql = require('mysql');

// exports.base = (sql, data, callback) => {
//     var dbconfig = require('../config/db');
//     const connection = mysql.createConnection(dbconfig.mysql);
//     connection.connect();
//     connection.query(sql, data, function (error, results, fields) {
//         var type = 1
//         console.log("error:",error)
//         if (error) { type = 0 };
//         //   callback(results);
//         callback({
//             results: results,
//             type: type
//         })
//         console.log("链接成功");
//     });
//     connection.end();
// }